//
//  SelectShopping+net.m
//  星期6
//
//  Created by 宗镇荣 on 16/2/25.
//  Copyright © 2016年 zzr. All rights reserved.
//

#import "SelectShopping+net.h"
#import "NetDefine.h"
#import "AFNetworking.h"

@implementation SelectShopping (net)

+ (void)requestWithPageNumber:(NSInteger)page WithAppId:(NSInteger)appId successBlock:(SuccessBlock)block {
    
        NSString *urlString = [NSString stringWithFormat:kShoppingUrl, appId];
    
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        [manager GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
            
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSDictionary *dataDict = dict[@"data"];
            NSArray *itemArray = dataDict[@"items"];
            NSMutableArray *tempArray = [[NSMutableArray alloc] init];
            for (NSDictionary *subDict in itemArray) {
                SelectShopping *model = [[SelectShopping alloc] initWithDictionary:subDict error:nil];
                [tempArray addObject:model];
            }
            block(tempArray, nil);
            
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            
            block(nil,error);
        }];

        


    
}

@end
